<template>
	<view class="page">
		<!-- 头部背景 -->
		<view class="head-bg">
			<view class="head-user">
				<view class="user">
				</view>
				<view class="exchange" @click="onConsumeRecord">
					<text>消费明细</text>
					<text class="iconfont icon-more"></text>
				</view>
			</view>
			<view class="wallet-balance">
				<view class="wallet">
					<text class="number">￥{{userInfo.money}}</text>
					<text><text class="iconfont icon-qianbao" style="margin-right: 20rpx;"></text>当前余额</text>
				</view>
			</view>
			<view class="bg">
				<image src="/static/integral_bg1.png" mode=""></image>
			</view>
		</view>
		<!-- 钱包充值 -->
		<view class="wallet-recharge">
			<view class="recharge-title">
				<text>钱包充值</text>
			</view>
			<view class="recharge-list">
				<view class="list" v-for="(item,index) in payList" 
				:class="{'action':index===subscript}"
				:key="index" @click="onPay(index,item.pay_price,item.pay_give)">
					<view class="price">
						<text>{{item.pay_price}}元</text>
					</view>
					<view class="give">
						<text>送{{item.pay_give}}元</text>
					</view>
				</view>
			</view>
		</view>
		<view class="recharge-btn">
			<view class="btn" @tap="go()">立即充值 ￥{{price}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:[],
				payList:[],
				subscript:0,
				price:100,
				cates:'',
				give:'',
			};
		},
		methods:{
			/**
			 * 消费明细点击
			 */
			onConsumeRecord(){
				uni.navigateTo({
					url: '/pages/ConsumeRecord/ConsumeRecord'
				})
			},
			onPay(subscript,price,give){
				this.subscript = subscript
				this.price = price
				this.give=give
			},
			//去充值
			go(){
				let price = this.price;
				let give = this.give;
				this.$http.post('recharge/pay', {
					price:price,
					give:give,
				},{}).then(res => {
					var order = res.data.data.order
					if(res.data.code == 200){
						uni.redirectTo({
							url: '/pages/CashierDesk/CashierDesk?order_id=' + order.order_no +
								"&pay_price=" + order.pay_price,
						})
					}else{
						uni.showToast({
							title:'充值失败'
						},1500)
					}
				})
			}
		},
		onReady() {
			this.userInfo = uni.getStorageSync('userInfo');
		},
		onLoad() {
			this.$http.get('recharge/list', {
			},{}).then(res => {
				this.payList = res.data.data
			})
		}
	}
</script>

<style scoped lang="scss">
	@import 'MyWallet.scss';
</style>
